package com.owen.rabbitmq;

import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicLong;

@Component
public class Tut3Sender implements Runnable {

    @Autowired
    private RabbitTemplate template;

    @Autowired
    private FanoutExchange fanout;

    private AtomicLong atomicLong=new AtomicLong(0L);

    @Override
    public void run() {
        while (true){
            long l = atomicLong.addAndGet(1L);
            template.convertAndSend(fanout.getName(),"","thread"+l);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
